package api

import (
	"github.com/gin-gonic/gin"
	"monitoring-api/service"
)

// GetArea 获取用户地区分布
func GetArea(c *gin.Context) {
	var service service.GetUserAreaService
	res := service.Count()
	c.JSON(200, res)
}

// GetBrowser 获取用户地区分布
func GetBrowser(c *gin.Context) {
	var service service.GetUserBrowserService
	res := service.Count()
	c.JSON(200, res)
}

func GetErrorsLogs(c *gin.Context) {
	var service service.GetErrLogsService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Query()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}

func GetActionsLogs(c *gin.Context) {
	var service service.GetActionLogsService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Query()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}

func GetReqLogs(c *gin.Context) {
	var service service.GetReqLogsService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Query()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}

func GetPerLogs(c *gin.Context) {
	var service service.GetPerLogsService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Query()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}
